<%@ Page Language="VB" AutoEventWireup="false" CodeFile="EditStat.aspx.vb" 
    Inherits="Statistics_EditStat" Title="Bridgwater Sports | Edit Stats"
    MasterPageFile="~/Default.master" Theme="ClubSite" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxT" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript">
function showModalPopupViaClient(ev) {
    ev.preventDefault();
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.show();
}
// Add click handlers for buttons to show and hide modal popup on pageLoad
function pageLoad() {
    $addHandler($get("showModalBatting"), 'click', showModalPopupViaClient);
    $addHandler($get("showModalBowling"), 'click', showModalPopupViaClient);        
}

</script>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Path="~/js/CricketBLL.js" />
        </Scripts>
    </asp:ScriptManager>
    <div class="fullwidth">
        <table cellspacing="0" cellpadding="0" width="100%">
            <tr> 
                <td>
                    <asp:HyperLink ID="AllStats" runat="server" Text="All Statistics" NavigateUrl="~/CricketStats/Default.aspx" /> &raquo;
                    <asp:HyperLink ID="hlBcGame" runat="server" Text="" NavigateUrl="~/CricketStats/Game.aspx" /> &raquo;
                </td>
            </tr>
        </table>
    </div>
    <div class="fullwidth">
        <div style="width: 98%; border: Solid 1px Gray; padding: 5px;">
            <div style="float: left;">
            <img src="../images/Info.png" alt="info" width="32" height="32" style="margin: 0 5px 0px 0;" /></div>
            <div style="float: left;">Enter in batsmen and bowlers scores, if the player is not in the list, click
                add player.
                <br />
                If you don't have all the data, enter in what you have and come back to do the rest.    
            </div>
        </div>
        <h2><asp:Label ID="lblGameTitle" runat="server"></asp:Label> Stats</h2><br />
        
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnCreateNewPlayer" />
            <asp:AsyncPostBackTrigger ControlID="UpdateStats" />
        </Triggers>
        <ContentTemplate>
        <div style="width: 100%; text-align: right;">
            <asp:Button ID="btnUpdateStats2" runat="server" Text="Update Statistics" 
                OnClick="UpdateStats_Click" />
        </div>
        <div id="batting">
            <h4>Batting</h4>
            
            <asp:ListView ID="lvBattingStats" runat="server">
                <LayoutTemplate>
                    <table style="width: 100%;">
                        <tr style="text-align: left;">
                            <th style="width: 25px;">&nbsp;</th>
                            <th>Player&nbsp;<a href="#" id="showModalBatting">Add Player</a></th>
                            <th>DNB</th>
                            <th>N.O</th>
                            <th>How Out</th>
                            <th>Bowler's Name</th>
                            <th>Mins</th>
                            <th>N.Balls</th>
                            <th>Fours</th>
                            <th>Sixes</th>
                            <th>Runs</th>
                        </tr>
                        <asp:PlaceHolder runat="server" id="itemPlaceHolder"></asp:PlaceHolder>
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
                    <tr>
                        <td>
                            <asp:Label runat="server" ID="lblBatNum" Text='<%#Eval("BatNumber")%>'></asp:Label>
                        </td>
                        <td>
                            <asp:HiddenField ID="hidPlayerId" runat="server" Value='<%# Eval("PlayerId") %>' />
                            <asp:DropDownList ID="ddlPlayers" runat="server" Width="200"
                                DataValueField="PlayerId" DataTextField="PlayerName">
                            </asp:DropDownList>
                        </td>
                        <td>
                            <asp:CheckBox ID="chkDNB" AutoPostBack="true" ValidationGroup='<%# Eval("BatNumber")%>' 
                                OnCheckedChanged="chkDNB_CheckChanged" runat="server" Checked='<%# Eval("DNB")%>' />
                        </td>
                        <td>
                            <asp:CheckBox ID="chkNO" AutoPostBack="true" ValidationGroup='<%# Eval("BatNumber")%>' 
                                OnCheckedChanged="chkNO_CheckChanged" runat="server" Checked='<%# Eval("NotOut")%>' />
                        </td>
                        <td>
                            <asp:HiddenField ID="hidHowOut" runat="server" Value='<%# Eval("HowOut") %>' />
                            <asp:DropDownList ID="ddlHowOut" runat="server" Width="100"
                                DataValueField="PlayerId" DataTextField="PlayerName"
                                AppendDataBoundItems="true">
                            </asp:DropDownList>
                        </td>
                        <td>
                            <asp:TextBox ID="txtBowler" runat="server" Width="100" Text='<%# Eval("BowlersName") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:TextBox ID="txtMins" runat="server" MaxLength="3" Width="30" Text='<%# Eval("MinutesInBat") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:TextBox ID="txtBallsFaced" runat="server" MaxLength="4" Width="30" Text='<%# Eval("BallsFaced") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:TextBox ID="txtFours" runat="server" MaxLength="3" Width="30" Text='<%# Eval("FoursHit") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:TextBox ID="txtSixes" runat="server" MaxLength="3" Width="30" Text='<%# Eval("SixesHit") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:TextBox ID="txtBatRuns" runat="server" MaxLength="3" Width="50" Text='<%# Eval("RunsScored") %>'></asp:TextBox>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:ListView>
        </div> 
        
        <div id="bowling">
            <h4>Bowling</h4>
            
            <asp:ListView ID="lvBowlingStats" runat="server">
                <LayoutTemplate>
                    <table style="width: 100%;">
                        <tr style="text-align: left;">
                            <th style="width: 25px;">&nbsp;</th>
                            <th>Player&nbsp;<a href="#" id="showModalBowling">Add Player</a></th>
                            <th>Overs</th>
                            <th>Maidens</th>
                            <th>Runs</th>
                            <th>Wickets</th>
                            <th>Catches</th>
                        </tr>
                        <asp:PlaceHolder runat="server" id="itemPlaceHolder"></asp:PlaceHolder>
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
                    <tr>
                        <td>
                            <asp:Label runat="server" ID="lblBowlNum" Text='<%# Eval("BowlerNumber") %>'></asp:Label>
                        </td>
                        <td>
                            <asp:HiddenField ID="hidPlayerId" runat="server" Value='<%# Eval("PlayerId") %>' />
                            <asp:DropDownList ID="ddlPlayers" runat="server" Width="200"
                                DataValueField="PlayerId" DataTextField="PlayerName"
                                AppendDataBoundItems="true">
                                <asp:ListItem>Select one...</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                        <td>
                            <asp:TextBox ID="txtOvers" runat="server" MaxLength="2" Width="50" Text='<%# Eval("OversBowled") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:TextBox ID="txtMaidens" runat="server" MaxLength="2" Width="50" Text='<%# Eval("Maidens") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:TextBox ID="txtRuns" runat="server" MaxLength="4" Width="50" Text='<%# Eval("Runs") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:TextBox ID="txtWickets" runat="server" MaxLength="3" Width="50" Text='<%# Eval("Wickets") %>'></asp:TextBox>
                        </td>
                        <td>
                            <asp:TextBox ID="txtCatches" runat="server" MaxLength="3" Width="30" Text='<%# Eval("Catches") %>'></asp:TextBox>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:ListView>
        </div> 
        
            </ContentTemplate>
        </asp:UpdatePanel>
        
        &nbsp;<asp:Label ID="ErrorLabel" runat="server" ForeColor="Red" Font-Bold="true" Font-Size="14" EnableViewState="false"></asp:Label><br />
        <asp:Button ID="UpdateStats" runat="server" Text="Update Statistics" /></div>

    <asp:Button runat="server" ID="hiddenTargetControlForModalPopup" Style="display: none" />
    <ajaxT:modalpopupextender runat="server" 
        ID="programmaticModalPopup" 
        BehaviorID="programmaticModalPopupBehavior"
        TargetControlID="hiddenTargetControlForModalPopup" 
        PopupControlID="programmaticPopup"
        CancelControlID="imgCloseModal"  
        BackgroundCssClass="modalBackground" 
        DropShadow="True" 
        PopupDragHandleControlID="programmaticPopupDragHandle"
        RepositionMode="RepositionOnWindowScroll">
    </ajaxT:modalpopupextender>
    <asp:Panel runat="server" CssClass="modalPopup" ID="programmaticPopup"
        Style="display: none; width: 350px;">
        <asp:Panel runat="Server" ID="programmaticPopupDragHandle" 
            Style="cursor: move; background-color: #DDDDDD; border: solid 1px Gray; color: Black; 
            text-align: center; height: 25px;">
            <div style="float: left; padding: 3px 0 0 5px;">
                <strong>Add a new player</strong>
            </div>
            <div style="float: right; padding: 3px 3px 0px 3px;">
                <asp:ImageButton ID="imgCloseModal" runat="server" style="cursor: pointer;" ImageUrl="~/images/close-modal.gif" />
            </div>
        </asp:Panel>
        
        <div style="padding: 5px;">
            <table style="width: 100%;">
                <tr>
                    <td style="width: 70px">Player Name</td>
                    <td>
                        <asp:TextBox ID="txtNewPlayerName" Width="85%" runat="server" AutoCompleteType="None"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                         ControlToValidate="txtNewPlayerName" ErrorMessage="*" CssClass="fieldValidator"
                         ValidationGroup="CreatePlayer"></asp:RequiredFieldValidator>
                        </td>
                </tr>
            </table>
            <div style="text-align: right; margin-top: 5px;">
                <asp:Button ID="btnCreateNewPlayer" runat="server" Text="Create Player" 
                  ValidationGroup="CreatePlayer" />
            </div>
        </div>
    </asp:Panel>
    
    <asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="0">
        <ProgressTemplate>
            <div style="position: fixed; z-index: 1000; right: 25px; top: 1px; 
                padding: 5px; background-color: White;">
                Loading...
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
</asp:Content>